package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingBaseInterfaceDAO;
import com.gx.ring.entity.UserLog;

public class ULInterfaceImplDAO implements RingBaseInterfaceDAO<UserLog>{
	
	private Connection conn = null;
	
	public ULInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}
	
	@Override
	public List<UserLog> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_userlog WHERE PHONENUMBER=? ";
		List<UserLog> ls = new ArrayList<>();
		UserLog usl = new UserLog();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			usl = saveResult(rs);
			ls.add(usl);
		}
		rs.close();
		pst.close();
		return ls;
	}



	@Override
	public UserLog saveResult(ResultSet rs) throws SQLException {
		UserLog usl = new UserLog();
		usl.setAdmincode(rs.getString("ADMINCODE"));
		usl.setAdtype(rs.getLong("ADTYPE"));
		usl.setChargeflag(rs.getLong("CHARGEFLAG"));
		usl.setDescription(rs.getString("DESCRIPTION"));
		usl.setLocalid(rs.getLong("LOCALID"));
		usl.setLogid(rs.getLong("LOGID"));
		usl.setLogtime(rs.getTimestamp("LOGTIME"));
		usl.setModulecode(rs.getString("MODULECODE"));
		usl.setNetkind(rs.getLong("NETKIND"));
		usl.setNewadcalleditem(rs.getString("NEWADCALLEDITEM"));
		usl.setNewaditem(rs.getString("NEWADITEM"));
		usl.setNewttlid(rs.getLong("NEWTTLID"));
		usl.setOldadcalleditem(rs.getString("OLDADCALLEDITEM"));
		usl.setOldaditem(rs.getString("OLDADITEM"));
		usl.setOlditem(rs.getString("OLDITEM"));
		usl.setOldttlid(rs.getLong("OLDTTLID"));
		usl.setOpenmodulecode(rs.getString("OPENMODULECODE"));
		usl.setOpenoperator(rs.getLong("OPENOPERATOR"));
		usl.setOperatetype(rs.getLong("OPERATETYPE"));
		usl.setOperator(rs.getLong("OPERATOR"));
		usl.setPhonenumber(rs.getString("PHONENUMBER"));
		usl.setReason(rs.getString("REASON"));
		usl.setReasoncode(rs.getLong("REASONCODE"));
		usl.setRemark(rs.getString("REMARK"));
		usl.setServicetype(rs.getLong("SERVICETYPE"));
		usl.setUsdpip(rs.getString("USDPIP"));
		usl.setUserplatformtype(rs.getLong("USERPLATFORMTYPE"));
		return usl;
	}

}
